package com.splant.android.smart.UILevel;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.splant.android.R;

import java.util.List;

/**
 * Created by Administrator on 2016/5/7.
 */
public class System_Bluetooth_DeviceList_Adapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private List<BluetoothDevice> deviceList;

    public System_Bluetooth_DeviceList_Adapter(Context context, List<BluetoothDevice> deviceList) {
        this.mInflater = LayoutInflater.from(context);
        this.deviceList = deviceList;
    }

    @Override
    public int getCount() {
        return deviceList.size();
    }

    @Override
    public Object getItem(int i) {
        return deviceList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = mInflater.inflate(R.layout.system_bluetooth_devicelist_adapter_item, null);
            holder = new ViewHolder();
            holder.deviceNameAddress = (TextView) view.findViewById(R.id.deviceNameAddrList);
            view.setTag(holder);
        } else
            holder = (ViewHolder) view.getTag();

        String deviceNameAddr = deviceList.get(i).getName() + " " + deviceList.get(i).getAddress();
        holder.deviceNameAddress.setText(deviceNameAddr);
        return view;
    }

    public final class ViewHolder {
        public TextView deviceNameAddress;
    }
}
